package com.hlhj.carview.module

import android.content.Context
import com.example.mymvp.log
import com.example.mymvp.mvp.BaseModule
import com.hlhj.carview.Iview.UserView
import com.hlhj.carview.bean.MyBaseBean
import com.hlhj.carview.bean.UserInfoBean
import com.hlhj.carview.http.Apis
import com.hlhj.carview.http.BaseAction2
import com.hlhj.carview.http.CustomAction
import com.hlhj.carview.http.LoadingAction
import com.hlhj.carview.utils.LoadingUtil
import com.lzy.okgo.model.Response
import io.reactivex.disposables.Disposable

/**
 * Created by Never Fear   on 2018\12\18 0018.
Never More....
 */
class UserModule :BaseModule {
     var listener:UserView?=null
    //获取用户信息
    fun getUser(c:Context){
        Apis?.getUserInfo()
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<UserInfoBean>>(c){
                                override fun httpSuccess(t: Response<UserInfoBean>) {
                                    log("fhp","网络过来")
                                    listener?.setUser(t.body())
                                }

                                override fun acheSuccess(t: Response<UserInfoBean>) {
                                    listener?.setUser(t.body())
                                    log("fhp","缓存过来")
                                }
                            })
                }
    }
    //改变头像
    fun changeHead(head:String,c:Context){
        Apis?.changeHead(head)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<MyBaseBean>>(c){
                                override fun httpSuccess(t: Response<MyBaseBean>) {
                                    listener?.setChangeResult(t.body())
                                }

                                override fun acheSuccess(t: Response<MyBaseBean>) {
                                }
                            })
                }
    }
}